package carcassonne.game.deck;

import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class Deck<T> {

    public final String name;

    public final int priority;

    public final List<T> Cards;

    public Deck(String name, int priority, List<T> cards) {
        this.name = name;
        this.priority = priority;
        Cards = cards;
    }

    protected int CardIndex = 0;

    public void Shuffle() {

        ThreadLocalRandom random = ThreadLocalRandom.current();

        for (int times = 0; times < 4; times++) {
            for (int i = 0; i < Cards.size(); i++) {
                int r = random.nextInt(Cards.size());
                T temp = Cards.get(i);
                Cards.set(i, Cards.get(r));
                Cards.set(r, temp);
            }
        }
        CardIndex = 0;
    }

    public boolean HasNext() {
        return CardIndex < Cards.size() - 1;
    }

    public T Current() {
        return Cards.get(CardIndex);
    }

    public T Next() {
        CardIndex++;
        return Cards.get(CardIndex);
    }

    public T Previous() {
        CardIndex--;
        return Cards.get(CardIndex);
    }

    public int RemainingCount() {
        return Cards.size() - CardIndex;
    }
}
